package com.witframework.core;



import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;


public class WitInitBaseAppListener  implements ServletContextListener {
	private static Log log = LogFactory.getLog(WitInitBaseAppListener.class);
	
	public void contextInitialized(final ServletContextEvent evt) {			
			String initializer=ApplicationProperties.getProperty("application.initializer","");			
			String[] initializerClassNames=StringUtils.split(initializer,",");
			AppInitializer appInitializer=null;
			for(String className:initializerClassNames){
				log.info("执行初始化类: "+className);
				try {
					appInitializer=(AppInitializer)Class.forName(className).newInstance();
					appInitializer.execute();
					log.info(className+": 初始化类执行完成!");
				}catch(Exception e){
					e.printStackTrace();
					log.info(className+": 初始化类执行失败!");
					log.trace(appInitializer,e);
				}
				
			}		
				
	}	
	public void contextDestroyed(final ServletContextEvent evt) { 
		
	}	
}
